<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'artist-project-form',
	'enableAjaxValidation'=>false,
        'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'title'); ?>
		<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'title'); ?>
	</div>
	<div class="row">
<?php 
$projete_images = new CActiveDataProvider('ProjectImage',array(
    'criteria'=>array(
        'condition'=>'project='.$model->id,
        //'order'=>'create_time DESC',
        //'with'=>array('author'),
    ),
));
echo $form->labelEx($model,'image');
echo CHtml::link('Add Image','javascript:;',array('id'=>'add_project_image_btn'));

$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'project-image-grid',
    'dataProvider'=> $projete_images,
    //'filter'=>  ProjectImage::model(),
    'summaryText'=> '',
    'selectableRows' => false,
    'hideHeader'=> true,
    'filterPosition'=>'footer',
    //'hasFooter'=> false,
    'columns'=>array(
        'id',
        array('name'=>'image','type' => 'raw','value'=>'CHtml::image($data->thumb,$data->image,array("width"=>"70","height"=>"60"))'),
        array(
            'class'=>'CButtonColumn',
            'template'=>'{delete}',
//            'viewButtonUrl'=>'Yii::app()->createUrl("/projectImage/view", array("id" => $data["id"]))',
//            'viewButtonLabel'=> '',
//            'viewButtonImageUrl'=> '',
//            'updateButtonImageUrl'=> '',
//            'updateButtonLabel'=> '',
            'deleteButtonUrl'=>'Yii::app()->createUrl("/projectImage/delete", array("id" => $data["id"]))',
        ),
    ),
)); 
?>
</div>
	<div class="row">
		<?php echo $form->labelEx($model,'description'); ?>
		<?php echo $form->textArea($model,'description',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'description'); ?>
	</div>

	<div class="row">
            <?php
                $artist_array = CHtml::listData(Artist::model()->findAll(), "id", "name");
                ?>
                <?php echo $form->labelEx($model,'artist'); ?>
                <?php echo $form->listBox($model,'artist',$artist_array); ?>
                <?php echo $form->error($model,'artist'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'tag'); ?>
		<?php echo $form->textField($model,'tag',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'tag'); ?>
	</div>
    <!--<div class="row">
            <?php
                $home_array = CHtml::listData(Home::model()->findAll(), "id", "name");
                ?>
                <?php echo $form->labelEx($model,'show_home'); ?>
                <?php echo $form->listBox($model,'show_home',$home_array); ?>
                <?php echo $form->error($model,'show_home'); ?>
	</div>-->
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); 
echo '<div id="add_project_image_box">';
$projectImage = new ProjectImage;
$projectImage->project = $model->id;
echo $this->renderPartial('/projectImage/_form', array('model'=> $projectImage));
echo '</div>';
?>

</div><!-- form -->
<script type="text/javascript">
$(function(){
    $('#add_project_image_btn').click(
        function(){
            $('#add_project_image_box').show();
        }
    );
    $('#close_project_image_box_btn').click(
        function(){
            $('#add_project_image_box').hide();
        }
    );
});
</script>